var xmlhttp=false;
var queryURL = new Array();
var queryFunc = new Array();
var query_length = 0;
try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
     } catch (e) {
      try {
       xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) {
       xmlhttp = null;
      }
     }
    if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
        try {
            xmlhttp = new XMLHttpRequest();
        } catch (e) {
            xmlhttp=null;
        }
    }
    if (!xmlhttp && window.createRequest) {
        try {
            xmlhttp = window.createRequest();
        } catch (e) {
            xmlhttp=null;
        }
    }

function SendRequest(sURL, hFunc, pos)
{
	if (sURL == null || hFunc == null) {
		alert("Null call");
		return;
	}
    if (xmlhttp != null) {
    	if (xmlhttp.readyState > 0 && xmlhttp.readyState < 4) {
    		queryURL[query_length] = sURL;
    		queryFunc[query_length] = hFunc;
    		query_length++;
    		return;
    	}
        xmlhttp.open("GET", sURL,true);
        xmlhttp.onreadystatechange=function() {
        if (xmlhttp.readyState==4) {
            var xmlDoc=xmlhttp.responseXML;
            if (xmlDoc == null) {
                if (window.DOMParser) {
                  var parser=new DOMParser();
                  xmlDoc=parser.parseFromString(xmlhttp.responseText,"text/xml");
                } else // Internet Explorer
                {
                  xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
                  xmlDoc.async="false";
                  xmlDoc.loadXML(xmlhttp.responseText);
                }
            }
            hFunc(xmlDoc);
            if (query_length) {
            	if (pos == null) pos = 0;
            	if (pos == query_length) {
            		queryURL = new Array();
            		queryFunc = new Array();
            		query_length = 0;
            		return;
            	}
            	SendRequest(queryURL[pos], queryFunc[pos], pos + 1);
            }
         };
        }
        xmlhttp.send(null);
    }
}

function SendAction(sURL, data, hFunc, pos)
{
	if (sURL == null || hFunc == null) {
		alert("Null call");
		return;
	}
    if (xmlhttp != null) {
    	if (xmlhttp.readyState > 0 && xmlhttp.readyState < 4) {
    		queryURL[query_length] = sURL;
    		queryFunc[query_length] = hFunc;
    		query_length++;
    		return;
    	}
        xmlhttp.open("POST", sURL,true);
        xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        xmlhttp.onreadystatechange=function() {
        if (xmlhttp.readyState==4) {
            var xmlDoc=xmlhttp.responseXML;
            if (xmlDoc == null) {
                if (window.DOMParser) {
                  var parser=new DOMParser();
                  xmlDoc=parser.parseFromString(xmlhttp.responseText,"text/xml");
                } else // Internet Explorer
                {
                  xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
                  xmlDoc.async="false";
                  xmlDoc.loadXML(xmlhttp.responseText);
                }
            }
            hFunc(xmlDoc);
            if (query_length) {
            	if (pos == null) pos = 0;
            	if (pos == query_length) {
            		queryURL = new Array();
            		queryFunc = new Array();
            		query_length = 0;
            		return;
            	}
            	SendRequest(queryURL[pos], queryFunc[pos], pos + 1);
            }
         };
        }
        xmlhttp.send(data);
    }
}
